Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-401

Captured variables should be read-only

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.3
    • 3.4.0
    • None

    Description

      WHAT:
      When a lambda captures local variables, these are copied into the lambda frame and behave as local variables within the lambda's scope. It would be convenient to alter this so that captured variables could be made read-only and reject side-effect operators at parsing time.

      WHY:
      This is an element of surprise for users with a Java background since captured variables must be final. It is also surprising when users expect dynamic (non lexical) scoping and would expect side effects to be carried thru scopes.
      The examples below illustrates the 2 ways this can be surprising.

      let x = -42;
      const f = y -> x += y; // x is implicitly declared as a copy in the lambda 'f' frame
      f(42);
      // x is still -42
      

      HOW:
      By introducing a new feature flag aptly named 'constCapture'. This feature flag determines whether captured variables are const or not (default).

      Attachments

        Issue Links

          Activity

            People

              henrib Henri Biestro
              henrib Henri Biestro
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: